package com.yanqu.road.server.cmd.tradewar;

import com.yanqu.road.entity.tradewar.CrossTradeWarWantedRecord;
import com.yanqu.road.logic.pb.CrossTradeWarPb;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.manager.tradewar.CrossTradeWarActivity;
import com.yanqu.road.server.manager.union.activitygroup.Cross2UnionActivityGroupMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.pb.tradewar.TradeWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.tradewar.CrossTradeWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_CROSS_TRADE_WAR_WANTED_LIST, desc = "跨服商战通缉列表")
public class CrossTradeWarWantedListCmd extends CrossUnionCommand {
    private int activityId;
    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossTradeWarProto.CrossTradeWarWantedListReqMsg reqMsg = CrossTradeWarProto.CrossTradeWarWantedListReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        //通缉列表
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, userId);
        CrossTradeWarActivity activity = CrossTradeWarMgr.getActivity(activityId, groupId);
        if (activity == null){
            return;
        }
        TradeWarProto.TradeWarWantedListMsg.Builder listMsg = activity.getTradeWarWantedListMsg(activityId,userId,serverId);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_CROSS_TRADE_WAR_WANTED_LIST, listMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
        //通缉记录
        List<CrossTradeWarWantedRecord> recordList = activity.getTradeWarWantedRecordList(activityId, userId, serverId);
        pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_CROSS_TRADE_WAR_WANTED_RECORD_LIST, CrossTradeWarPb.parseCrossTradeWarWantedRecordListMsg(recordList));
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
